package com.toKnow.service.impl;

import com.toKnow.mapper.UserInfoMapper;
import com.toKnow.model.entity.UserInfo;
import com.toKnow.service.WelcomeService;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class WelcomeServiceImpl implements WelcomeService {
    @Resource
    private UserInfoMapper userInfoMapper;

    @Override
    public String getUsernameFromAccount(String account) {
        String username = account; // 输入用户名登录
        if(account != null && account.contains("@")){ // 输入邮箱登录
            username = userInfoMapper.selectActiveUsernameByEmail(account);
        }
        return username;
    }

    @Override
    public Integer confirmLogin(String username, String userpwd) {
        UserInfo userInfo = userInfoMapper.selectActiveUserByUsernameAndUserpwd(username, DigestUtils.md5Hex(userpwd));
        if(userInfo == null){
            return 0;
        }else {
            return userInfo.getId();
        }
    }
}
